//
//  SettingTableViewCell.m
//  CommonFrame
//
//  Created by Bang-guo on 15/7/28.
//  Copyright (c) 2015年 guobang. All rights reserved.
//

#import "SettingTableViewCell.h"

@implementation SettingTableViewCell

-(void)writeCell:(NSString *)str {
    
    UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(10, 5, 30, 30)];
    UILabel *lable = [[UILabel alloc] initWithFrame:CGRectMake(50, 5, WIDTH - 40, 30)];
    [self.contentView addSubview:imageV];
    [self.contentView addSubview:lable];
    if ([str isEqualToString:@"我的收藏"]) {
        
        imageV.image = [UIImage imageNamed:@"collection.png"];
        lable.text = str;
        
        
    }
    if ([str isEqualToString:@"清除缓存"]) {
        
        imageV.image = [UIImage imageNamed:@"delete.png"];
        lable.text = str;
        
        
    }
    if ([str isEqualToString:@"夜间模式"]) {
        
        imageV.image = [UIImage imageNamed:@"nightImage.png"];
        lable.text = str;
        UISwitch *switchView = [[UISwitch alloc] initWithFrame:CGRectMake(WIDTH - 70, 7, 50, 28.0f)];
        switchView.backgroundColor = [UIColor whiteColor];
//        2.设置UISwitch的初始化状态
        
        switchView.on = YES;//设置初始为ON的一边
        
//        3.UISwitch事件的响应
        
        [switchView addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
        [self.contentView addSubview:switchView];
        
    }
    if ([str isEqualToString:@"联系我们"]) {
        
        imageV.image = [UIImage imageNamed:@"aboutUs.png"];
        lable.text = str;
        
        
    }
    
    
}

-(void)switchAction:(UISwitch *)switchA {
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];


    NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
    if ([@"on" isEqualToString:[userDefaults objectForKey:@"isNight"]]) {

        [userDefaults setObject:@"off" forKey:@"isNight"];

    } else {
        [userDefaults setObject:@"on" forKey:@"isNight"];

    }
    [notificationCenter postNotificationName:@"changeNight" object:@"on"];
    [self.myDelegate nightChange];
    
    
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
